<template>
	<view class="page_box" style="margin-top: -10px; padding-top: 10px" :style="{ height: windowHeight }">
		<u-collapse v-if="list.length" style="margin-bottom: 5px">
			<component is="msgCell" :list="list"> </component>
		</u-collapse>
		<u-empty v-if="page >= 1 && !list.length" text="数据为空" mode="list"></u-empty>
		<u-loadmore v-else :status="loadStatus" />'
	</view>
</template>

<script>
	import msgCell from  "@/pages/customerManagement/pushMessage/components/msgCell.vue"
export default {
	data: () => ({
		windowHeight: '0',
		list: [],
		// 底部加载状态
		loadStatus: 'loadmore',
		// 第几页
		page: 1,
		// 每页显示数量
		limit: 15,
		// 类型文本
		statusText: ['', '任务', '日志', 'oa审批', '公告', '撤回', '日程', 'crm消息'],
	}),
	components:{msgCell},
	methods: {
		// 获取列表
		async getList() {
			this.loadStatus = 'loading';
			let data = {
				page: this.page,
				limit: this.limit,
			};

			let res = await this.$api.common.getUserPushMessage(data);
			if (res.code == 200) {
				let list = res.data.list || [];
				if (this.page === 1) {
					this.list = list;
				} else {
					this.list.push(...list);
				}
				// list为空，说明没有更多数据了，显示没有更多数据的提示
				if (!list.length || (this.page == 1 && list.length <= res.data.totalRow)) {
					this.loadStatus = 'nomore';
				}
			}
		},
	},
	watch: {},

	// 周期函数--监听页面加载
	onLoad(option) {
		this.getList();
	},
	// 周期函数--监听页面初次渲染完成
	onReady() {},
	// 周期函数--监听页面显示
	onShow() {
		console.log('onshow onshow onshow onshow ');
		let self = this;
		uni.getSystemInfo({
			success: function (res) {
				self.windowHeight = res.windowHeight + 'px';
			},
		});
		this.getList();
	},
	// 周期函数--监听页面隐藏
	onHide() {},
	// 周期函数--监听页面卸载
	onUnload() {},
	// 页面处理函数--监听用户下拉动作
	async onPullDownRefresh() {
		this.page = 1;
		await this.getList();
		uni.stopPullDownRefresh();
	},
	// 页面处理函数--监听用户上拉触底
	async onReachBottom() {
		this.page++;
		await this.getList();
		uni.stopPullDownRefresh();
	},
	// 监听自定义标题栏按钮事件
	onNavigationBarButtonTap(e) {
		uni.navigateTo({
			url: e.url + '?params=add',
		});
	},
	// 页面处理函数--监听页面滚动
	/* onPageScroll(event) {}, */
	// 页面处理函数--用户点击右上角分享
	/* onShareAppMessage(options) {}, */
};
</script>

<style scoped>
.page_box {
	height: 500px;
	background-color: #efefef;
}
</style>
